package com.online.servlet.shop;

import com.online.pojo.menu;
import com.online.pojo.merchant;
import com.online.service.user.Impl.merchantServiceImpl;
import com.online.service.user.merchantService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class removeMenuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id= Integer.parseInt(req.getParameter("id"));
        String user_name=req.getParameter("user_name");
        String shop_name=req.getParameter("shop_name");
        merchantService merchantService=new merchantServiceImpl();
        try {
            merchantService.del(id);
            merchant shop;
            shop=merchantService.loginUsername(user_name);
            List<menu> list=new ArrayList<menu>();
            merchantService.select(list,shop_name);
            req.setAttribute("menu",list);
            req.setAttribute("shop_name",shop.getShop_name());
            req.setAttribute("user_name",shop.getUser_name());
            req.setAttribute("account",shop.getAccount());
            req.getRequestDispatcher("/jsp/Merchantback.jsp").forward(req,resp);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
